#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 叶建伟
   @Email: yejw46507@hundsun.com
   @Time: 2023/5/12 16:28
   @File: dataTest.py
"""
from threading import Thread

from faker import Faker

from DataTest.databases import MysqlUtil
from DataTest.sqlmontage.SQLMontage import get_sql_key, montage_sql_value, read_file
from DataTest.sqlmontage.clientInfo import client_info

fake = Faker(locale='zh_CN')


def montage_sql(**kwargs):
    table = kwargs.get('table')
    sql_list = kwargs.get('sql_list')
    sql = read_file(table)
    for key, value in sql.items():
        table_value = {}
        for key_1, value_1 in value[0].items():
            keyLower = key_1.lower()
            table_value.update({keyLower: value_1})
        table_key = get_sql_key(table=table)
        values = montage_sql_value(table=table_value, sql_list=sql_list)
        print('SQL: ' + table_key.lower()+values+';')
        return table_key.lower()+values+';'

class NewThread(Thread):
    def __init__(self):
        Thread.__init__(self)  # 必须步骤

    def run(self):  # 入口是名字为run的方法
        for i in range(500):
            sql_list = client_info()
            sql = montage_sql(table='amlwl_daytime_client_today', sql_list=sql_list)
            db.execsql(sql)
        print("这个新线程中的任务结束啦")


if __name__ == "__main__":
    db = MysqlUtil('root', 'root', '10.20.37.217', port=33061)
    # threadList = []
    # for i in range(8):
    #     threadList.append(NewThread())
    # for i in threadList:
    #     i.start()
    for i in range(50):
        daytime_client_name = '中国铁建大桥工程局集团建筑装配科技有限公司'
        daytime_id_no = '1234569794'
        client_type = '1'
        id_type = '33'
        sql_list = client_info()

        sql_list.update(
            {'daytime_client_name': daytime_client_name, 'daytime_id_no': daytime_id_no, 'client_type': client_type,
             'id_type': id_type})
        sql = montage_sql(table='amlwl_daytime_client_today', sql_list=sql_list)
        db.execsql(sql)







